﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;//引用命名空間
using System.Data.SqlClient;//引用命名空間

public partial class myWented : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string sqlConnString = "Data Source=asdf80730.no-ip.org;Initial Catalog=project;Persist Security Info=True;User ID=sa;Password=P@ssword";//設定資料庫名稱與路徑
        SqlConnection cnn = new SqlConnection(sqlConnString);//建立Connection 物件
        int MId = Convert.ToInt32(Session["MId"]);

        cnn.Open();//使用Open開啟資料庫

        SqlCommand cmd = new SqlCommand("SELECT COUNT(Wanted.WId) FROM Wanted WHERE Wanted.MId=" + MId, cnn);
        SqlDataReader sqlreader;
        sqlreader = cmd.ExecuteReader();


        if (sqlreader.Read())
        {
            int WantedQty = sqlreader.GetSqlInt32(0).Value;
            //Response.Write("<script language=JavaScript>alert('" + "Session[Mid]=" + MId + ",WantedQty=" + WantedQty + "')</script>");

            if (WantedQty > 0)
                MultiView1.ActiveViewIndex = 0;
            else
                MultiView1.ActiveViewIndex = 1;

        }
        else
        {
            //  btnDeal.Visible = true;
            Response.Write("<script language=JavaScript>alert('登入失敗')</script>");
        }
        cnn.Close();
    }
    protected void Page_PreInit(object sender, EventArgs e)
    {
        if (Session["MId"] == null)//會員
        {
            this.Page.MasterPageFile = "~/MasterPage.master";
            Response.Redirect("login.aspx");
        }
        else       //一般使用者
            this.Page.MasterPageFile = "~/LoginedMasterPage.master";
    }
   
    protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
    {


    }
}